<?php $this->load->view('frontend/header_layout'); ?>
<div class="row">
    <?php echo $breackcrumb; ?>

    <div class="well">
        <?php
        if ($result !== 0) {

            $topic_id = $this->uri->segment(3);

            foreach ($result as $thread) {
                echo '<h3 style="padding:0px;margin:0px;">' . $thread->thread_title . '</h3>';
                ?>
                <!--start dialog box-->

                <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>      					                         

                <style type="text/css">

                    .dialog{
                        border:5px solid #666;
                        padding:10px;
                        background:#fff;
                        position:absolute;
                        display:none;
                    }
                    .dialog label{
                        display:inline-block;
                        color:#cecece;
                    }
                </style>
                <script type="text/javascript">
                    function codeBinsAddEvent(obj,type,fn){
                        if(obj.attachEvent){
                            if(type == "load"){
                                obj.attachEvent('on'+type, fn);
                            }
                            else{
                                obj.attachEvent('onreadystatechange', fn);
                            }
                        }
                        else obj.addEventListener(type,fn,false)
                    };
                    function codeBinsAddLoadEvent(fn){
                        codeBinsAddEvent(document.addEventListener&&!window.addEventListener?document:window,'load',fn)
                    };
                    function codeBinsAddReadyEvent(fn){
                        codeBinsAddEvent(document,'DOMContentLoaded',fn)
                    };
                    

                    <!--Date
                    /*<script type="text/javascript">
                    <!--
                    function current_date(){
                    var currentDate = new Date()
                    var day = currentDate.getDate()
                    var month = currentDate.getMonth() + 1
                    var year = currentDate.getFullYear()
                    document.write("<b>" + day + "-" + month + "-" + year + "</b>");
                    }

                </script>-->*/
                <!--end of date-->

                </script>


                <body Body Params>
                    <div id="panel">

                        <br>
                        <!-- Dialog Box-->

                        <?php
                        $title = array(
                            'name' => 'reply_title',
                            'value' => set_value('rep_title'),
                            'id' => 'input01',
                            'required' => '',
                            'placeholder' => 'Title...',
                            'class' => 'input-xlarge'
                        );
                        $content = array(
                            'name' => 'reply_content',
                            'value' => set_value('rep_content'),
                            'id' => 'input01',
                            'required' => '',
                            'placeholder' => 'Content...',
                            'class' => 'input-xlarge',
                            'rols' => '20',
                            'cols' => '20'
                        );
                        $publish_dated = array(
                            'name' => 'reply_dated',
                            'value' => set_value('rep_dated'),
                            'id' => 'input01',
                            'required' => '',
                            'class' => 'input-xlarge'
                        );
                        $author = array(
                            'name' => 'reply_author',
                            'value' => set_value('rep_author'),
                            'id' => 'input01',
                            'required' => '',
                            'class' => 'input-xlarge'
                        );
                        $status = array(
                            'name' => 'reply_status',
                            'value' => set_value('rep_status', '0'),
                            'id' => 'input01',
                            'required' => '',
                            'class' => 'input-xlarge'
                        );
                        $thread_id = array(
                            'name' => 'reply_thread',
                            'value' => set_value('thread_id'),
                            'id' => 'input01',
                            'required' => '',
                            'class' => 'input-xlarge'
                        );
                        ?>


                        <div class="dialog" id="myform">
                            <?php echo form_open('chat_topic/insert_re'); ?>


                            <div class="control-group">
                                <label class="control-label" for="input01">Title </label>
                                <div class="controls">
                                    <?php echo form_input($title); ?>
                                </div>
                            </div>


                            <div class="control-group">
                                <label class="control-label" for="input01">Content </label>
                                <div class="controls">
                                    <?php echo form_textarea($content); ?>
                                </div>
                            </div>


                            <input type="hidden" id="date" name="date">

                            <script type="text/javascript">
                                document.getElementById('date').value = Date();
                            </script>


                            <div class="control-group">
                                <div class="controls">


                                    <input type="hidden" name="thread_id" value="<?php echo $this->uri->segment(3); ?>" />

                                </div>
                            </div>

                            <div class="control-group">
                                <div class="controls">
                                    <?php echo form_input(array('type' => 'hidden', 'name' => 'author', $this->session->userdata('user_login'))); ?>
                                </div>
                            </div>

                            <div class="control-group">
                                <div class="controls">
                                    <?php echo form_input(array('type' => 'hidden', 'name' => 'status', $status)); ?>
                                </div>
                            </div>
                            <div align="center">
                                <?php echo form_submit('btn_reply', 'Submit', 'class="btn btn-primary"'); ?>
                            </div>
                            </form>
                        </div>
                    </div>   

                </body>
                <script type="text/javascript">
                    $(function() {
                    $(".button").click(function() {
                    $("#myform #valueFromMyButton").text($(this).val().trim());
                    $("#myform input[type=text]").val('');
                    $("#valueFromMyModal").val('');
                    $("#myform").show(500);
                    });
                    $("#btnOK").click(function() {
                    $("#valueFromMyModal").val($("#myform input[type=text]").val().trim());
                    $("#myform").hide(400);
                    });
                    });// BOTTOM OF PAGE
                </script>

                <!--end up-->

                <?php
                $authors = $this->chat_topic_m->get_author($thread->thread_author);
                foreach ($authors as $author) {
                    echo '<p><small><b>By:</b>_' . $author->user_name . '</smal> | ';
                }
                echo '<small><b>Date:</b>_' . $thread->thread_dated . '</small></p>';
                echo '<p>' . $thread->thread_content . '</p>';
                ?>

                <input type="button" class="button btn btn-info pull-right btn-mini" value="Reply " id="btn1" />

            </div>
            <div class="span12">		
                <table>
        <?php
        if ($all_reply) {
            foreach ($all_reply as $row) {
                $authors = $this->chat_topic_m->get_author($row->rep_author);
                foreach ($authors as $author) {
                    ?>
                                <tr>
                                    <td class="span2"><b>User Profile</b>
                    <?php echo '<p><small><b>' . $author->firstName . ' ' . $author->lastName . '<b></small></p>'; ?>	

                                    </td>
                                    <td class="span10 well well-small pull-right ">	
                    <?php echo '<b>' . $row->rep_title . '</b>'; ?>
                                        <?php
                                        echo '<p><small><b>By:</b>_' . $author->user_name . ' | ';
                                        echo '<b>Date:</b>_' . $row->rep_dated . '</small></p>';
                                        ?>

                                        <p ><?php echo $row->rep_content; ?></p>
                                    </td>

                                </tr>		
                <?php
                }
            }
        } else {
            echo "Don't have any replies yet";
        }
        ?>
                </table>

            </div>
        </div>
        <?php
    }
}
?>